
import { ZExcel } from '../index';
import { operates } from './operate-items';
import { OperateBase } from './common/operate-base';
import './index.less';

export class Toolsbar{
    protected operateInstance: OperateBase[] = [];
    protected renderTimeEle: HTMLDivElement;
    constructor(protected ele: HTMLElement, protected tableInstance: ZExcel) {
        this.init();
    }
    public init() {
        for(let items of operates) {
            let groupEle = document.createElement('div');
            groupEle.setAttribute('class', 'z-tools-group');
            for(let operate of items) {
                let instance = new operate();
                this.operateInstance.push(instance);
                groupEle.append(instance.getDom());
            }
            this.ele.appendChild(groupEle);
        }
        this.renderTimeEle = document.createElement('div');
        this.renderTimeEle.setAttribute('class', 'z-excel-render-item');
        // this.ele.append(this.renderTimeEle);
        // let tableContainer = document.querySelector('.z-table-container') as HTMLElement;
        // let intance = ZExcel.create(tableContainer);
        let hook = this.tableInstance.activeTable.getHook();
        hook.renderTime.add((time: number) => {
            // this.renderTimeEle.innerText = `${time}ms`;
            // @ts-ignore
            document.querySelector('.z-render-info').querySelector('.z-table-render-time').querySelector('.value').innerText = `${time}ms`;
        });
        this.operateInstance.forEach(_itme => {
            _itme.setInstance(this.tableInstance.activeTable);
            _itme.afterDomInit();
        });
    }
}